program main
   implicit none
   integer,parameter::maxcode=1000,maxstack=1000
   integer::data(maxstack)=0,i=1,cnt,sp=1
   character(len=maxcode)::code
   character::tmp
   read(*,"(A)")code
   do while(i<=len_trim(code))
      select case(code(i:i))
      case(">"); sp=sp+1
      case("<"); sp=sp-1
      case("+"); data(sp)=data(sp)+1
      case("-"); data(sp)=data(sp)-1
      case("."); write(*,"(A1)",advance="no")char(data(sp))
      case(","); read(*,"(A1)")tmp;data(sp)=ichar(tmp)
      case("[","]")
         if(code(i:i)=="[".and.data(sp)==0.or.code(i:i)=="]".and.data(sp)/=0)then
            cnt=1
            do while(cnt/=0)
               i=i+merge(1,-1,data(sp)==0)
               if(code(i:i)=="]") cnt=cnt-merge(1,-1,data(sp)==0)
               if(code(i:i)=="[") cnt=cnt+merge(1,-1,data(sp)==0)
            end do
            cycle
         end if
      end select 
      i=i+1
   end do
end program main